package com.jlf.controller.engine.entity.domain;

import com.jlf.controller.engine.entity.field.FieldDetail;
import com.jlf.controller.engine.entity.index.IndexDetail;
import com.jlf.core.annotation.Domain;
import com.jlf.core.engine.constant.SchemaConstant;
import com.jlf.core.engine.domain.SchemaDomainDO;
import com.jlf.core.engine.domain.SchemaFieldDO;
import com.jlf.core.engine.domain.SchemaIndexDO;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

/**
 * 模型领域的详情输出
 *
 * @author wujr
 * 2023/7/18
 * @version 1.0
 * 【变更历史】
 * [wujr 2023/7/18 1.0 新增]
 */
@Getter
@Setter
public class SchemaDomainDetail {
    private Long id;
    /**
     * 领域的编码，具有唯一性
     * 用于：注解：{@link Domain#code()}
     */
    private String domainCode;
    /**
     * 领域名称
     * 用于：注解：{@link Domain#name()}
     */
    private String domainName;
    /**
     * 该领域的数据表名称
     * 用于：注解：{@link Domain#table()}
     */
    private String domainTable;
    /**
     * 领域的版本号
     */
    private Integer domainVersion;
    /**
     * 数据库，主键id的类型 {@link SchemaConstant.Jdbc.id}
     */
    private Integer dbIdType;
    /**
     * 领域的包
     */
    private String domainPackage;
    /**
     * 该模型领域的管理接口的路径
     */
    private String restfulPath;
    /**
     * 是否需要对记录进行乐观锁
     */
    private Boolean optimisticLocker;
    private Integer status;
    private Integer priority;

    private List<FieldDetail> fields;
    private List<IndexDetail> indexes;

    public void addField(SchemaFieldDO field){
        if (this.fields == null){
            this.fields = new ArrayList<>();
        }
        this.fields.add(new FieldDetail(field));
    }
    public void addIndex(SchemaIndexDO index){
        if (this.indexes == null){
            this.indexes = new ArrayList<>();
        }
        this.indexes.add(new IndexDetail(index));
    }

    public SchemaDomainDetail(SchemaDomainDO record){
        this.id = record.getId();
        this.domainCode = record.getDomainCode();
        this.domainName = record.getDomainName();
        this.domainTable = record.getDomainTable();
        this.domainVersion = record.getDomainVersion();
        this.dbIdType = record.getDbIdType();
        this.domainPackage = record.getDomainPackage();
        this.restfulPath = record.getRestfulPath();
        this.optimisticLocker = record.getOptimisticLocker();
        this.status = record.getStatus();
        this.priority = record.getPriority();
    }

}
